package com.yuan.springcloud.producer;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author YouYuan
 * @date 2020/4/7 18:07
 */
@Component
public class RabbitMessageSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    //交换机
    @Value("${amqp.exchange.direct}")
    private String exchange;

    public void sendLogMessage(int i){
        String msg = i + " :message: " + new Date();
        System.out.println(msg);
        rabbitTemplate.convertAndSend(exchange, "log", msg);
    }

    public void sendEmailMessage(int i){
        String msg = i + " :message: " + new Date();
        System.out.println(msg);
        rabbitTemplate.convertAndSend(exchange, "email", msg);
    }
}
